package com.sas.hnn;

import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;

public class HeaderRow extends Fragment implements OnClickListener{

	/**
	 * @uml.property  name="tAG"
	 */
	private String TAG= HeaderRow.class.getSimpleName();
	
	/**
	 * @uml.property  name="b_name"
	 * @uml.associationEnd  
	 */
	private Button b_name;

	/**
	 * @uml.property  name="b_age"
	 * @uml.associationEnd  
	 */
	private Button b_age;

	/**
	 * @uml.property  name="b_street"
	 * @uml.associationEnd  
	 */
	private Button b_street;

	/**
	 * @uml.property  name="b_locale"
	 * @uml.associationEnd  
	 */
	private Button b_locale;
	/**
	 * @uml.property  name="mContentView"
	 * @uml.associationEnd  
	 */
	private View mContentView;
	
	@Override
	public void onAttach(Activity activity) {
		// TODO Auto-generated method stub
		super.onAttach(activity);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		mContentView= inflater.inflate(R.layout.header_row, null);
		
		initialisiere();
		return mContentView;
//		return super.onCreateView(inflater, container, savedInstanceState);
	}

	private void initialisiere() {
		b_name= (Button) mContentView.findViewById(R.id.b_name);
		b_age= (Button) mContentView.findViewById(R.id.b_age);
		b_street= (Button) mContentView.findViewById(R.id.b_street);
		b_locale= (Button) mContentView.findViewById(R.id.b_locale);
		
		b_name.setOnClickListener(this);
		b_age.setOnClickListener(this);
		b_street.setOnClickListener(this);
		b_locale.setOnClickListener(this);
	}

	/*
	 * Tap auf Spaltenbeschriftun sortiert die Liste.
	 * in der staischen var Person.sortWhat wird reingeschrieben, was sortiert werden soll
	 */
	public void onClick(View v) {
		PersonList frag= (PersonList) getFragmentManager().findFragmentById(R.id.frag_rows);
		switch (v.getId()) {
		case R.id.b_name:
			Persons.sortWhat="name";
			break;
		case R.id.b_age:
			Persons.sortWhat="age";
			break;
		case R.id.b_street:
			Persons.sortWhat="street";
			break;
		case R.id.b_locale:
			Persons.sortWhat="locale";
			break;
		default:
			Persons.sortWhat="none";
			break;
		}
		frag.sort();
		
	}

}
